﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Baimasoft.FrameWork.Base;
using Baimasoft.Manage.SqlServerDAL;

public partial class DataBase_ParamTypeEdit : System.Web.UI.Page
{
    ParamType MyPT = new ParamType();

    public  string sEditStatus = "1";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            try
            {
                sEditStatus = this.Request.QueryString["EditStatus"].ToString().Trim();
                if (sEditStatus == "2")
                {
                    string sID = this.Request.QueryString["ID"].ToString().Trim();
                    SqlDataReader MySDR = MyPT .ReadParamType ("id =" + sID);
                    if (MySDR.Read())
                    {
                        Code.Text = MySDR["Code"].ToString().Trim();
                        Name.Text = MySDR["Name"].ToString().Trim();
                        status.Text = MySDR["Status"].ToString().Trim();
                    }
                }
                else
                {
                }
            }
            catch
            {
            }
        }
    }


    protected void SaveData_ServerClick(object sender, EventArgs e)
    {
        try
        {
            string sName = Name.Text.ToString().Trim();
            string sCode = Code.Text.ToString().Trim();
            string sstatus = status.SelectedValue.ToString().Trim();

            string sPersID = (string)Session["Baimasoft_Pers_ID"];
            string sOrgID = (string)Session["Baimasoft_Dept_ID"];

            sEditStatus = this.Request.QueryString["EditStatus"].ToString().Trim();

            if (sEditStatus == "1")
            {
                int iback = MyPT.InsertParamType(sCode, sName, sstatus, sPersID, sOrgID);
                if (iback > 0)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('保存成功!');window.close();</script>");
                    return;
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('保存失败!');</script>");
                    return;
                }
            }
            else
            {
                int iback = MyPT.UpdateParamType(sCode, sName, sstatus, sPersID, sOrgID, this.Request.QueryString["ID"].ToString().Trim());
                if (iback > 0)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改成功!');window.close();</script>");  //window.opener.location.reload();
                    return;
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改失败!');</script>");
                    return;
                }
            }
        }
        catch
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('操作失败!');</script>");
            return;
        }
    }
}
